package com.sbtr.controller;


import com.sbtr.business.user.service.IUserAllowCountService;
import com.sbtr.common.PageDto;
import com.sbtr.common.Response;
import com.sbtr.open.user.dto.UserAllowCountDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author oujh5
 */
@RestController
@RequestMapping("/user/allow-count")
@ApiIgnore
public class UserAllowCountController {

    @Autowired
    private IUserAllowCountService userAllowCountService;

    @ApiOperation(value = "根据账号批量查找", notes = "根据账号批量查找", httpMethod = "POST")
    @RequestMapping(value = "/search-by-uids", method = RequestMethod.POST)
    public Response<List<UserAllowCountDto>> searchByUserIds(@RequestBody List<String> userIds) {

        List<UserAllowCountDto> list = userAllowCountService.searchByUserIds(userIds);
        return Response.success(list);
    }


    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "GET")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public Response<PageDto<UserAllowCountDto>> search(@RequestParam(name = "userId", required = false) String userId,
                                                       @RequestParam("page") Long currPage, @RequestParam("pageSize") Long pageSize) {
        return Response.success(userAllowCountService.search(userId, currPage, pageSize));
    }


    @ApiOperation(value = "根据账号批量删除", notes = "根据账号批量删除", httpMethod = "POST")
    @RequestMapping(value = "/batch-delete", method = RequestMethod.POST)
    public Response<Boolean> batchDelete(@RequestBody List<String> userIds) {

        boolean b = userAllowCountService.batchDelete(userIds);
        if (b) {
            return Response.success("删除成功", b);
        } else {
            return Response.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "删除失败");
        }
    }

    @ApiOperation(value = "批量保存", notes = "批量保存", httpMethod = "POST")
    @RequestMapping(value = "/batch-save", method = RequestMethod.POST)
    public Response<Boolean> batchSave(@RequestBody List<UserAllowCountDto> dtoList) {
        return Response.success(userAllowCountService.batchSave(dtoList));
    }

}

